﻿using Gtkj.CMS.Common;
using Gtkj.CMS.Model.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Gtkj.CMS.App.Models
{
    public class CacheHelp
    {
        static readonly string MainDomain = System.Configuration.ConfigurationManager.AppSettings["MainDomain"];
        static readonly string Protocol = System.Configuration.ConfigurationManager.AppSettings["Protocol"];

        /// <summary>
        /// 取得后台菜单
        /// </summary>
        /// <returns></returns>
        //public static List<Model.Menu> GetMenus(string role)
        //{
        //    List<Model.Menu> menus = Common.CacheContainer.GetData<List<Model.Menu>>(Model.Enums.CacheEnum.后台菜单.ToString());
        //    if (menus != null && menus.Count() > 0)
        //        return menus;
        //    BLL.MenuService MenuService = new BLL.MenuService();
        //    menus = MenuService.LoadEntities(s => s.Display && s.Remark.Contains(role)).OrderByDescending(s => s.Orderby).ToList();
        //    Common.CacheContainer.SetData(Model.Enums.CacheEnum.后台菜单.ToString(), menus, 3600 * 24 * 30);
        //    return menus;
        //}


        ///// <summary>
        ///// 将会话用户加入缓存
        ///// </summary>
        ///// <param name="guid"></param>
        ///// <returns></returns>
        //public static Model.UserInfo GetUserName(string guid)
        //{
        //    Model.UserInfo u = null;
        //    List<Model.UserInfo> users = Common.CacheContainer.GetData<List<Model.UserInfo>>(Model.Enums.CacheEnum.用户信息.ToString());
        //    if(users!=null&& users.Count>0)
        //    {
        //        u = users.FirstOrDefault(s => s.Guid == guid);
        //        if (u != null)
        //            return u;
        //    }
            
        //    BLL.UserInfoService UserInfoService = new BLL.UserInfoService();
        //    u = UserInfoService.LoadEntities(s => s.Guid == guid).FirstOrDefault();
        //    if (u == null)
        //        return u;
        //    if(users==null)
        //        users = new List<Model.UserInfo>();
        //    users.Add(u);
        //    Common.CacheContainer.SetData(Model.Enums.CacheEnum.用户信息.ToString(),users,8*3600);
        //    return u;
        //}


        /// <summary>
        /// 删除指定缓存
        /// </summary>
        /// <param name="ce"></param>
        public static void Clear(string ce)
        {
            Common.CacheContainer.SetData(ce, null, -1);
            Common.CacheContainer.ClearUp();
        }
       

       

    }
}